package fun.util.daohelper;

import org.springframework.beans.factory.ListableBeanFactory;

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: bin
 * Date: Jan 23, 2006
 * Time: 10:40:46 PM
 * To change this template use File | Settings | File Templates.
 */
public class SpringUtils {


    public static <B> B getBean( ListableBeanFactory appContext, Class<? extends B> typeClass ) {
        Map beans = appContext.getBeansOfType( typeClass );
        if ( beans.size() == 1 ) {
            return (B)beans.values().iterator().next();
        }
        else {
            throw new IllegalStateException( beans.size() + " beans found of type: " + typeClass.getName() );
        }
    }
}
